#!/usr/bin/env python3
# coding:utf-8
import sys
from loguru import logger

logger.debug("this test")
logger.add(sys.stdout, format="[{time} {level}] {message}")
logger.debug("this test 10")

logger.remove(handler_id=None)
logger.add(sys.stderr, format="[{time} {level}] {message}")
logger.debug("this test 11 ")

logger.remove(handler_id=None)
log_format = "[{time:YYYYMMDD-HH:mm:ss.SSS} {level}] {message}"
logger.add(sys.stderr, format=log_format)
logger.debug("this test 12")

# 高亮颜色
# 移除默认的处理器
logger.remove()
# 自定义日志格式
log_format = (
    "<green>{time:YYYY-MM-DD HH:mm:ss.SS}</green> | "
    "<level>{level: <8}</level> | "
    "<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
)

# 添加自定义格式化的处理器
logger.add(sys.stderr, format=log_format, enqueue=True, colorize=True)
logger.debug("this test 13")
logger.info("this test 14")
logger.error("this test 15")

# 2023-12-26 16:21:36.204 | DEBUG    | __main__:<module>:6 - this test
# [2023-12-26T16:21:36.205378+0800 DEBUG] this test
# [20231226-16:21:36.206 DEBUG] this test
